home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_templates.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  43.7 KB  |  1,558 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Skin -> Templates functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 15th April 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25.  
  26.  
  27. $idx = new ad_settings();
  28.  
  29.  
  30. class ad_settings {
  31.  
  32.     var $base_url;
  33.  
  34.     function ad_settings() {
  35.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  36.  
  37.         switch($IN['code'])
  38.         {
  39.             case 'add':
  40.                 $this->add_templates();
  41.                 break;
  42.                 
  43.             case 'edit':
  44.                 $this->do_form('edit');
  45.                 break;
  46.                 
  47.             case 'edit2':
  48.                 $this->show_file();
  49.                 break;
  50.                 
  51.             case 'doedit':
  52.                 $this->do_edit();
  53.                 break;
  54.                 
  55.             case 'remove':
  56.                 $this->remove();
  57.                 break;
  58.                 
  59.             case 'tools':
  60.                 $this->tools();
  61.                 break;
  62.                 
  63.             case 'editinfo':
  64.                 $this->edit_info();
  65.                 break;
  66.                 
  67.             case 'export':
  68.                 $this->export();
  69.                 break;
  70.             
  71.             //-------------------------
  72.             default:
  73.                 $this->list_current();
  74.                 break;
  75.         }
  76.         
  77.     }
  78.     
  79.     function export()
  80.     {
  81.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  82.         
  83.         if ($IN['id'] == "")
  84.         {
  85.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  86.         }
  87.         
  88.         //+-------------------------------
  89.         
  90.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  91.         
  92.         if ( ! $row = $DB->fetch_row() )
  93.         {
  94.             $ADMIN->error("Could not query the information from the database");
  95.         }
  96.         
  97.         //+-------------------------------
  98.         
  99.         $archive_dir   = $INFO['base_dir']."/archive_out";
  100.         $templates_dir = $INFO['base_dir']."/style_templates/".$row['skid'];
  101.         
  102.         require $root_dir."sources/lib/tar.php";
  103.         
  104.         if (!is_dir($archive_dir))
  105.         {
  106.             $ADMIN->error("Could not locate $archive_dir, is the directory there?");
  107.         }
  108.         
  109.         if (!is_writeable($archive_dir))
  110.         {
  111.             $ADMIN->error("Cannot write in $archive_dir, CHMOD via FTP to 0755 or 0777 to enable this script to write into it. IBF cannot do this for you");
  112.         }
  113.         
  114.         if (!is_dir($templates_dir))
  115.         {
  116.             $ADMIN->error("Could not locate $templates_dir, is the directory there?");
  117.         }
  118.         
  119.         //+-------------------------------
  120.         // Attempt to copy the files to the
  121.         // working directory...
  122.         //+-------------------------------
  123.         
  124.         $l_name = preg_replace( "/\s{1,}/", "_", $row['skname'] );
  125.         
  126.         $new_dir = "tmpl-".$l_name;
  127.         
  128.         if ( ! $ADMIN->copy_dir($templates_dir, $archive_dir."/".$new_dir) )
  129.         {
  130.             $ADMIN->error( $ADMIN->errors );
  131.         }
  132.         
  133.         // Generate the config file..
  134.         
  135.         $file_content = "<?php\n\n".
  136.                         "\$config=array('author' => \"".addslashes($row['author'])."\", ".
  137.                         "'email'=>\"".addslashes($row['email'])."\", ".
  138.                         "'url'=>\"".addslashes($row['url'])."\")\n\n?".">";
  139.         
  140.         $FH = fopen($archive_dir."/".$new_dir."/"."conf.inc", 'w');
  141.         fwrite($FH, $file_content, strlen($file_content));
  142.         fclose($FH);
  143.         
  144.         // Add files and write tarball
  145.         
  146.         $tar = new tar();
  147.         
  148.         $tar->new_tar( $archive_dir, $new_dir.".tar" );
  149.         $tar->add_directory( $archive_dir."/".$new_dir );
  150.         $tar->write_tar();
  151.         
  152.         // Check for errors.
  153.         
  154.         if ($tar->error != "")
  155.         {
  156.             $ADMIN->error($tar->error);
  157.         }
  158.         
  159.         // remove original unarchived directory
  160.         
  161.         $ADMIN->rm_dir($archive_dir."/".$new_dir);
  162.         
  163.         $ADMIN->done_screen("Template Pack Export Created<br><br>You can download the tar-chive <a href='archive_out/{$new_dir}.tar' target='_blank'>here</a>", "Manage Template Sets", "act=templ" );
  164.         
  165.         
  166.     }
  167.     
  168.     //+--------------------------------------------------------------------------------
  169.     //+--------------------------------------------------------------------------------
  170.     
  171.     function tools_rebuildphp()
  172.     {
  173.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  174.         
  175.         
  176.         if ($IN['id'] == "")
  177.         {
  178.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  179.         }
  180.         
  181.         //+-------------------------------
  182.         
  183.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  184.         
  185.         if ( ! $row = $DB->fetch_row() )
  186.         {
  187.             $ADMIN->error("Could not query the information from the database");
  188.         }
  189.         
  190.         $templates_dir = $root_path."style_templates/".$IN['id'];
  191.         
  192.         $skin_dir     = $root_path."Skin/s".$IN['id'];
  193.         
  194.         $errors = array();
  195.         
  196.         $flag = 0;
  197.         
  198.         if (! file_exists( $root_path."style_templates/".$IN['id']."/config.php" ) )
  199.         {
  200.             $ADMIN->error("Could not locate the template set configuration file, make sure 'config.php' resides in the templates directory you are editing. If
  201.                            it is not there, you can copy one from another directory.");
  202.         }
  203.         
  204.         //+-------------------------------
  205.         
  206.         require $root_path."style_templates/".$IN['id']."/config.php";
  207.         
  208.         //+-------------------------------
  209.         
  210.         
  211.         if ( ! is_writeable($skin_dir) )
  212.         {
  213.             $ADMIN->error("Cannot write into '$skin_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  214.         }
  215.         
  216.         if ( ! is_writeable($templates_dir) )
  217.         {
  218.             $ADMIN->error("Cannot write into '$templates_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  219.         }
  220.         
  221.         if ( is_dir($templates_dir) )
  222.         {
  223.             if ( $handle = opendir($templates_dir) )
  224.             {
  225.             
  226.                 while (($filename = readdir($handle)) !== false)
  227.                 {
  228.                     if (($filename != ".") && ($filename != ".."))
  229.                     {
  230.                         if ( preg_match( "/^index\./", $filename ) )
  231.                         {
  232.                             continue;
  233.                         }
  234.                         
  235.                         //-------------------------------------------
  236.                     
  237.                         if ( preg_match( "/\.html$/", $filename ) )
  238.                         {
  239.                             
  240.                             $name = preg_replace( "/\.html$/", "", $filename );
  241.                             
  242.                             if ( file_exists($skin_dir."/".$name.".php") )
  243.                             {
  244.                                 if (! is_writeable($skin_dir."/".$name.".php") )
  245.                                 {
  246.                                     $errors[] = "Cannot write to $name".".php, skipping file...";
  247.                                     continue;
  248.                                 }
  249.                             }
  250.                             
  251.                             if ($FHD = fopen($templates_dir."/".$filename, 'r') )
  252.                             {
  253.                                 $text = fread($FHD, filesize($templates_dir."/".$filename) );
  254.                                 fclose($FHD);
  255.                             }
  256.                             else
  257.                             {
  258.                                 $errors[] = "Could not open $filename, skipping file...";
  259.                                 continue;
  260.                             }
  261.                             
  262.                             //----------------------------------------------------
  263.                             
  264.                             $need = count($skin[$name]);
  265.                             $start = 0;
  266.                             $end   = 0;
  267.                             
  268.                             if ($need < 1)
  269.                             {
  270.                                 $errors[] = "Error recalling function data for $filename, skipping...";
  271.                                 continue;
  272.                             }
  273.         
  274.                             // check to make sure the splitter tags are intact
  275.                             
  276.                             foreach($skin[$name] as $func_name => $data)
  277.                             {
  278.                                 if ( preg_match("/<!--\|IBF\|$func_name\|START\|-->/", $text) )
  279.                                 {
  280.                                     $start++;
  281.                                 }
  282.                                 
  283.                                 //+-------------------------------
  284.                                 
  285.                                 if ( preg_match("/<!--\|IBF\|$func_name\|END\|-->/", $text) )
  286.                                 {
  287.                                     $end++;
  288.                                 }
  289.                             }
  290.                             
  291.                             if ($start != $end)
  292.                             {
  293.                                 $errors[] = "Some start or end template splitter comments are missing in $filename, skipping file....";
  294.                                 continue;
  295.                             }
  296.                             
  297.                             if ($start != $need)
  298.                             {
  299.                                 $errors[] = "Some template splitter comments are missing in $filename, skipping file...";
  300.                                 continue;
  301.                             }
  302.                             
  303.                             //+-------------------------------
  304.                             // Convert the tags back to php native
  305.                             //+-------------------------------
  306.                             
  307.                             $text = $this->unconvert_tags($text);
  308.                             
  309.                             //+-------------------------------
  310.                             // Start parsing the php skin file
  311.                             //+-------------------------------
  312.                             
  313.                             $final = "<"."?php\n\n".
  314.                                      "class $name {\n\n";
  315.                             
  316.                             foreach($skin[$name] as $func_name => $data)
  317.                             {
  318.                             
  319.                                 $top = "\n\nfunction $func_name($data) {\n".
  320.                                        "global \$ibforums;\n".
  321.                                        "return <<<EOF\n";
  322.                                        
  323.                                 $bum = "\nEOF;\n}\n";
  324.                             
  325.                                 $text = preg_replace("/\s*<!--\|IBF\|$func_name\|START\|-->\s*\n/", "$top", $text);
  326.                                 
  327.                                 
  328.                                 //+-------------------------------
  329.                                 
  330.                                 $text = preg_replace("/\s*<!--\|IBF\|$func_name\|END\|-->\s*\n/", "$bum", $text);
  331.                             }
  332.                             
  333.                             $end = "\n\n}\n?".">";
  334.                             
  335.                             $final .= $text.$end;
  336.                             
  337.                             if ($fh = fopen( $skin_dir."/".$name.".php", 'w' ) )
  338.                             {
  339.                                 fwrite($fh, $final, strlen($final) );
  340.                                 fclose($fh);
  341.                             }
  342.                             else
  343.                             {
  344.                                 $errors[] = "Could not save information to $phpskin, please ensure that the CHMOD permissions are correct.";
  345.                             }
  346.                             
  347.                             $end   = "";
  348.                             $final = "";
  349.                             $top   = "";
  350.                             
  351.                         } // if *.php
  352.                         
  353.                     } // if not dir
  354.                     
  355.                 } // while loop
  356.                 
  357.                 closedir($handle);
  358.                 
  359.             }
  360.             else
  361.             {
  362.                 $errors[] = "Could not open directory $templates_dir for reading!";
  363.             }
  364.         }
  365.         else
  366.         {
  367.             $errors[] = "$templates_dir is not a directory, please check the \$root_path variable in admin.php";
  368.         }
  369.         
  370.         if (count($errors > 0))
  371.         {
  372.             $ADMIN->html .= $SKIN->start_table("Errors and warnings");
  373.         
  374.             $ADMIN->html .= $SKIN->add_td_basic( implode("<br>", $errors) );
  375.                                              
  376.             $ADMIN->html .= $SKIN->end_table();
  377.         }
  378.         
  379.         $ADMIN->done_screen("Source PHP Skin files updated from the editable templates", "Manage Template sets", "act=templ" );
  380.         
  381.         
  382.     }
  383.     
  384.     
  385.     
  386.     function edit_info()
  387.     {
  388.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  389.         
  390.         if ($IN['id'] == "")
  391.         {
  392.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  393.         }
  394.         
  395.         //+-------------------------------
  396.         
  397.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  398.         
  399.         if ( ! $row = $DB->fetch_row() )
  400.         {
  401.             $ADMIN->error("Could not query the information from the database");
  402.         }
  403.         
  404.         $final['skname'] = stripslashes($HTTP_POST_VARS['skname']);
  405.         
  406.         if (isset($HTTP_POST_VARS['author']))
  407.         {
  408.             $final['author'] = stripslashes($HTTP_POST_VARS['author']);
  409.             $final['email']  = stripslashes($HTTP_POST_VARS['email']);
  410.             $final['url']    = stripslashes($HTTP_POST_VARS['url']);
  411.         }
  412.         
  413.         $db_string = $DB->compile_db_update_string( $final );
  414.         
  415.         $DB->query("UPDATE ibf_tmpl_names SET $db_string WHERE skid='".$IN['id']."'");
  416.         
  417.         $ADMIN->done_screen("Template information updated", "Manage Template sets", "act=templ" );
  418.         
  419.     }
  420.     
  421.     //+-------------------------------
  422.     //+-------------------------------
  423.     
  424.     function do_edit()
  425.     {
  426.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  427.         
  428.         $text = stripslashes($HTTP_POST_VARS['template']);
  429.         
  430.         if ($IN['id'] == "")
  431.         {
  432.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  433.         }
  434.         
  435.         //+-------------------------------
  436.         
  437.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  438.         
  439.         if ( ! $row = $DB->fetch_row() )
  440.         {
  441.             $ADMIN->error("Could not query the information from the database");
  442.         }
  443.         
  444.         //+-------------------------------
  445.         
  446.         $real_name = preg_replace( "/\.html/", "", $IN['name'] );
  447.         
  448.         //+-------------------------------
  449.         
  450.         $template = $root_path."style_templates/".$IN['id']."/".$IN['name'];
  451.         $phpskin  = $root_path."Skin/s".$IN['id']."/".$real_name.".php";
  452.         
  453.         //+-------------------------------
  454.         
  455.         if (! file_exists( $root_path."style_templates/".$IN['id']."/config.php" ) )
  456.         {
  457.             $ADMIN->error("Could not locate the template set configuration file, make sure 'config.php' resides in the templates directory you are editing. If
  458.                            it is not there, you can copy one from another directory.");
  459.         }
  460.         
  461.         //+-------------------------------
  462.         
  463.         require $root_path."style_templates/".$IN['id']."/config.php";
  464.         
  465.         //+-------------------------------
  466.         
  467.         if ( ! is_writeable($template) )
  468.         {
  469.             $ADMIN->error("Cannot write into '$template', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  470.         }
  471.         
  472.         if ( ! is_writeable($phpskin) )
  473.         {
  474.             $ADMIN->error("Cannot write into '$phpskin', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  475.         }
  476.         
  477.         //+-------------------------------
  478.         // Ok, make sure we actually have
  479.         // some info to parse here.
  480.         //+-------------------------------
  481.         
  482.         if ($text == "")
  483.         {
  484.             $ADMIN->error("You can't delete the template in this manner");
  485.         }
  486.         
  487.         //+-------------------------------
  488.         // Swop back < and >
  489.         //+-------------------------------
  490.         
  491.         $text = preg_replace("/</", "<", $text);
  492.         $text = preg_replace("/>/", ">", $text);
  493.         $text = preg_replace("/&/", "&", $text);
  494.         
  495.         //+-------------------------------
  496.         // Convert \r to nowt
  497.         //+-------------------------------
  498.         
  499.         $text = preg_replace("/\r/", "", $text);
  500.         
  501.         //+-------------------------------
  502.         // Make sure we have enough subs
  503.         // left. Check to make sure we've
  504.         // not removed and start and end tags
  505.         //+-------------------------------
  506.         
  507.         $start = 0;
  508.         $end   = 0;
  509.         
  510.         $need = count($skin[$real_name]);
  511.         
  512.         //<!--|IBF|stats_header|END|-->
  513.         
  514.         // check to make sure the splitter tags are intact
  515.         
  516.         foreach($skin[$real_name] as $func_name => $data)
  517.         {
  518.             if ( preg_match("/<!--\|IBF\|$func_name\|START\|-->/", $text) )
  519.             {
  520.                 $start++;
  521.             }
  522.             
  523.             //+-------------------------------
  524.             
  525.             if ( preg_match("/<!--\|IBF\|$func_name\|END\|-->/", $text) )
  526.             {
  527.                 $end++;
  528.             }
  529.         }
  530.         
  531.         if ($start != $end)
  532.         {
  533.             $ADMIN->error("Some start or end template splitter comments are missing, please go back and try again");
  534.         }
  535.         
  536.         if ($start != $need)
  537.         {
  538.             $ADMIN->error("Some template splitter comments are missing, please go back and try again");
  539.         }
  540.         
  541.         //+-------------------------------
  542.         // Save the template back to disk
  543.         //+-------------------------------
  544.         
  545.         if ($fh = fopen( "$template", 'w' ) )
  546.         {
  547.             fwrite( $fh, $text, strlen($text) );
  548.             fclose($fh);
  549.         }
  550.         else
  551.         {
  552.             $ADMIN->error("Could not save information to $template, please ensure that the CHMOD permissions are correct.");
  553.         }
  554.         
  555.         //+-------------------------------
  556.         // Convert the tags back to php native
  557.         //+-------------------------------
  558.         
  559.         $text = $this->unconvert_tags($text);
  560.         
  561.         //+-------------------------------
  562.         // Start parsing the php skin file
  563.         //+-------------------------------
  564.         
  565.         $final = "<"."?php\n\n".
  566.                  "class $real_name {\n\n";
  567.         
  568.         foreach($skin[$real_name] as $func_name => $data)
  569.         {
  570.         
  571.             $top = "\n\nfunction $func_name($data) {\n".
  572.                    "global \$ibforums;\n".
  573.                    "return <<<EOF\n";
  574.                    
  575.             $bum = "\nEOF;\n}\n";
  576.         
  577.             $text = preg_replace("/\s*<!--\|IBF\|$func_name\|START\|-->\s*\n/", "$top", $text);
  578.             
  579.             
  580.             //+-------------------------------
  581.             
  582.             $text = preg_replace("/\s*<!--\|IBF\|$func_name\|END\|-->\s*\n/", "$bum", $text);
  583.         }
  584.         
  585.         $end = "\n\n}\n?".">";
  586.         
  587.         $final .= $text.$end;
  588.         
  589.         if ($fh = fopen( "$phpskin", 'w' ) )
  590.         {
  591.             fwrite($fh, $final, strlen($final) );
  592.             fclose($fh);
  593.         }
  594.         else
  595.         {
  596.             $ADMIN->error("Could not save information to $phpskin, please ensure that the CHMOD permissions are correct.");
  597.         }
  598.         
  599.         $ADMIN->done_screen("Template file updated", "Manage Templates in template set: {$row['skname']}", "act=templ&code=edit&id={$IN['id']}" );
  600.         
  601.     }
  602.     
  603.     //------------------------------------------------------------------------------------
  604.     //------------------------------------------------------------------------------------
  605.     
  606.     function tools()
  607.     {
  608.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  609.         
  610.         if ($IN['id'] == "")
  611.         {
  612.             $ADMIN->error("You must choose a valid skin file to perform this operation on");
  613.         }
  614.         
  615.         if ($IN['tool'] == 'conf')
  616.         {
  617.             $this->tools_conf();
  618.         }
  619.         else if ($IN['tool'] == 'tmpl')
  620.         {
  621.             $this->tools_build_tmpl();
  622.         }
  623.         else
  624.         {
  625.             $this->tools_rebuildphp();
  626.         }
  627.         
  628.     }
  629.     
  630.     //------------------------------------------------------------------------------------
  631.     
  632.     function tools_build_tmpl()
  633.     {
  634.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  635.         
  636.         // Rebuilds the skin.html editable files from the PHP source files
  637.         
  638.         $templates_dir = $root_path."style_templates/".$IN['id'];
  639.         
  640.         $skin_dir     = $root_path."Skin/s".$IN['id'];
  641.         
  642.         $errors = array();
  643.         
  644.         $flag = 0;
  645.         
  646.         
  647.         if ( ! is_writeable($skin_dir) )
  648.         {
  649.             $ADMIN->error("Cannot write into '$skin_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  650.         }
  651.         
  652.         if ( ! is_writeable($templates_dir) )
  653.         {
  654.             $ADMIN->error("Cannot write into '$templates_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  655.         }
  656.         
  657.         if ( is_dir($skin_dir) )
  658.         {
  659.             if ( $handle = opendir($skin_dir) )
  660.             {
  661.             
  662.                 while (($filename = readdir($handle)) !== false)
  663.                 {
  664.                     if (($filename != ".") && ($filename != ".."))
  665.                     {
  666.                     
  667.                         if ( preg_match( "/\.php$/", $filename ) )
  668.                         {
  669.                             
  670.                             $name = preg_replace( "/^(\S+)\.(\S+)$/", "\\1", $filename );
  671.                             
  672.                             if ( file_exists($templates_dir."/".$name.".html") )
  673.                             {
  674.                                 if (! is_writeable($templates_dir."/".$name.".html") )
  675.                                 {
  676.                                     $errors[] = "Cannot write to $name".".html, skipping file...";
  677.                                 }
  678.                             }
  679.                             
  680.                             $farray = file($skin_dir."/".$filename) or die("Could not open $skin_dir/$filename for reading");
  681.                             
  682.                             //$tfh = fopen($skin_dir."/".$filename , 'r')
  683.                             
  684.                             //----------------------------------------------------
  685.                             
  686.                             $functions = array();
  687.                             
  688.                             foreach($farray as $f)
  689.                             {
  690.                                 
  691.                                 // Skip javascript functions...
  692.                                 
  693.                                 if ( preg_match( "/<script/i", $f ) )
  694.                                 {
  695.                                     $script_token = 1;
  696.                                 }
  697.                                 
  698.                                 if ( preg_match( "/<\/script>/i", $f ) )
  699.                                 {
  700.                                     $script_token = 0;
  701.                                 }
  702.                                 
  703.                                 //-------------------------------
  704.                                 
  705.                                 if ($script_token == 0)
  706.                                 {
  707.                                     if ( preg_match( "/^function\s*([\w\_]+)\s*\((.*)\)/i", $f, $matches ) )
  708.                                     {
  709.                                         $functions[$matches[1]] = '';
  710.                                         $flag = $matches[1];
  711.                                         continue;
  712.                                     }
  713.                                 }
  714.                                     
  715.                                 if ($flag)
  716.                                 {
  717.                                     $functions[$flag] .= $f;
  718.                                     continue;
  719.                                 }
  720.                                  
  721.                             }
  722.                             
  723.                             //----------------------------------------------------
  724.                             
  725.                             $final = "";
  726.                             $flag  = 0;
  727.                             
  728.                             foreach($functions as $fname => $ftext)
  729.                             {
  730.                                 $final .= "<!--|IBF|$fname|START|-->\n\n";
  731.                                 
  732.                                 preg_match( "/return <<<EOF(.+?)EOF;/s", $ftext, $matches );
  733.                                 
  734.                                 $final .= $this->convert_tags($matches[1]);
  735.                                 
  736.                                 $final .= "\n\n<!--|IBF|$fname|END|-->\n\n";
  737.                             }
  738.                             
  739.                             $fh = fopen($templates_dir."/".$name.".html", 'w');
  740.                             fwrite( $fh, $final, strlen($final) );
  741.                             fclose($fh);
  742.                             
  743.                             $functions = array();
  744.                             
  745.                             //----------------------------------------------------
  746.                             
  747.                         } // if *.php
  748.                         
  749.                     } // if not dir
  750.                     
  751.                 } // while loop
  752.                 
  753.                 closedir($handle);
  754.                 
  755.             }
  756.             else
  757.             {
  758.                 $ADMIN->error("Could not open directory $skin_dir for reading!");
  759.             }
  760.         }
  761.         else
  762.         {
  763.             $ADMIN->error("$skin_dir is not a directory, please check the \$root_path variable in admin.php");
  764.         }
  765.         
  766.         $ADMIN->done_screen("Editable templates updated from source PHP skin files", "Manage Template sets", "act=templ" );
  767.         
  768.         if (count($errors > 0))
  769.         {
  770.             $this->html .= $SKIN->start_table("Errors and warnings");
  771.         
  772.             $this->html .= $SKIN->add_td_basic( implode("<br>", $errors) );
  773.                                              
  774.             $this->html .= $SKIN->end_table();
  775.         }
  776.         
  777.         
  778.     }
  779.     
  780.     //----------------------------------------------------
  781.     
  782.     
  783.     function tools_conf()
  784.     {
  785.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  786.         
  787.         // Rebuilds the config.php file (remaps function names and ($data) stuff
  788.         
  789.         $final = "<?"."php\n\n";
  790.         
  791.         $config_file = $root_path."style_templates/".$IN['id']."/config.php";
  792.         
  793.         $skin_dir    = $root_path."Skin/s".$IN['id'];
  794.         
  795.         if ( ! file_exists($config_file) )
  796.         {
  797.             $ADMIN->error("Could not locate the master config file in $config_file, is it there?");
  798.         }
  799.         
  800.         if ( ! is_writeable($config_file) )
  801.         {
  802.             $ADMIN->error("Cannot rewrite the master config file in $config_file, please check the CHMOD value - and if needed, set to 0777 via FTP");
  803.         }
  804.         
  805.         $script_token = 0;
  806.         
  807.         if ( is_dir($skin_dir) )
  808.         {
  809.             if ( $handle = opendir($skin_dir) )
  810.             {
  811.             
  812.                 while (($filename = readdir($handle)) !== false)
  813.                 {
  814.                     if (($filename != ".") && ($filename != ".."))
  815.                     {
  816.                     
  817.                         if ( preg_match( "/\.php$/", $filename ) )
  818.                         {
  819.                             
  820.                             $name = preg_replace( "/^(\S+)\.(\S+)$/", "\\1", $filename );
  821.                             
  822.                             $astart = "\$skin["."'$name'"."]";
  823.                             
  824.                             $farray = file($skin_dir."/".$filename) or die("Could not open $skin_dir/$filename for reading");
  825.                             
  826.                             foreach($farray as $f)
  827.                             {
  828.                                 
  829.                                 // Skip javascript functions...
  830.                                 
  831.                                 if ( preg_match( "/<script/i", $f ) )
  832.                                 {
  833.                                     $script_token = 1;
  834.                                 }
  835.                                 
  836.                                 if ( preg_match( "/<\/script>/i", $f ) )
  837.                                 {
  838.                                     $script_token = 0;
  839.                                 }
  840.                                 
  841.                                 //-------------------------------
  842.                                 
  843.                                 if ($script_token == 0)
  844.                                 {
  845.                                     if ( preg_match( "/^function\s*([\w\_]+)\s*\((.*)\)/i", $f, $matches ) )
  846.                                     {
  847.                                         $matches[2] = preg_replace( "/\'/", "\"", $matches[2] );
  848.                                     
  849.                                         $final .= $astart."['".$matches[1]."']"."   =   '".$matches[2]."';\n";
  850.                                     }
  851.                                 }
  852.                             }
  853.                         }
  854.                     }
  855.                 }
  856.                 
  857.                 closedir($handle);
  858.                 
  859.             }
  860.             else
  861.             {
  862.                 $ADMIN->error("Could not open directory $skin_dir for reading!");
  863.             }
  864.         }
  865.         else
  866.         {
  867.             $ADMIN->error("$skin_dir is not a directory, please check the \$root_path variable in admin.php");
  868.         }
  869.         
  870.         $final .= "?".">";
  871.         
  872.         $fh = fopen($config_file, 'w');
  873.         fwrite( $fh, $final, strlen($final) );
  874.         fclose($fh);
  875.         
  876.         $ADMIN->done_screen("Master configuration template file updated", "Manage Template sets", "act=templ" );
  877.         
  878.     }
  879.         
  880.     
  881.     //-------------------------------------------------------------
  882.     // Add images..
  883.     //-------------------------------------------------------------
  884.     
  885.     
  886.     function add_templates()
  887.     {
  888.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  889.         
  890.         if ($IN['id'] == "")
  891.         {
  892.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  893.         }
  894.         
  895.         //-------------------------------------
  896.         
  897.         if ( ! is_writeable($root_path.'style_templates') )
  898.         {
  899.             $ADMIN->error("The directory 'style_templates' is not writeable by this script. Please check the permissions on that directory. CHMOD to 0777 if in doubt and try again");
  900.         }
  901.         
  902.         if ( ! is_writeable($root_path.'Skin') )
  903.         {
  904.             $ADMIN->error("The directory 'Skin' is not writeable by this script. Please check the permissions on that directory. CHMOD to 0777 if in doubt and try again");
  905.         }
  906.         
  907.         //-------------------------------------
  908.         
  909.         if ( ! is_dir($root_path.'style_templates/'.$IN['id']) )
  910.         {
  911.             $ADMIN->error("Could not locate the original template set to copy, please check and try again");
  912.         }
  913.         
  914.         if ( ! is_dir($root_path.'Skin/s'.$IN['id']) )
  915.         {
  916.             $ADMIN->error("Could not locate the original template set to copy, please check and try again");
  917.         }
  918.         
  919.         //-------------------------------------
  920.         
  921.         $DB->query("SELECT * FROM ibf_tmpl_names WHERE skid='".$IN['id']."'");
  922.         
  923.         //-------------------------------------
  924.         
  925.         if ( ! $row = $DB->fetch_row() )
  926.         {
  927.             $ADMIN->error("Could not query that template set from the DB, so there");
  928.         }
  929.         
  930.         //-------------------------------------
  931.         
  932.         $row['skname'] = $row['skname'].".2";
  933.         
  934.         // Insert a new row into the DB...
  935.         
  936.         $final = array();
  937.         
  938.         foreach($row as $k => $v)
  939.         {
  940.             if ($k == 'skid')
  941.             {
  942.                 continue;
  943.             }
  944.             else
  945.             {
  946.                 $final[ $k ] = $v;
  947.             }
  948.         }
  949.         
  950.         $db_string = $DB->compile_db_insert_string( $final );
  951.         
  952.         $DB->query("INSERT INTO ibf_tmpl_names (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
  953.         
  954.         $new_id = $DB->get_insert_id();
  955.         
  956.         //-------------------------------------
  957.         
  958.         if ( ! $ADMIN->copy_dir( $INFO['base_dir'].'style_templates/'.$IN['id'] , $INFO['base_dir'].'style_templates/'.$new_id ) )
  959.         {
  960.             $DB->query("DELETE FROM ibf_tmpl_names WHERE skid='$new_id'");
  961.             
  962.             $ADMIN->error( $ADMIN->errors );
  963.         }
  964.         
  965.         //-------------------------------------
  966.         
  967.         if ( ! $ADMIN->copy_dir( $INFO['base_dir'].'Skin/s'.$IN['id'] , $INFO['base_dir'].'Skin/s'.$new_id ) )
  968.         {
  969.             $DB->query("DELETE FROM ibf_tmpl_names WHERE skid='$new_id'");
  970.             
  971.             $ADMIN->error( $ADMIN->errors );
  972.         }
  973.         
  974.         //-------------------------------------
  975.         // Pass to edit / add form...
  976.         //-------------------------------------
  977.         
  978.         $this->do_form('add', $new_id);
  979.     
  980.     }
  981.     
  982.     //-------------------------------------------------------------
  983.     // REMOVE WRAPPERS
  984.     //-------------------------------------------------------------
  985.     
  986.     function remove()
  987.     {
  988.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  989.         
  990.         //+-------------------------------
  991.         
  992.         
  993.         if ($IN['id'] == "")
  994.         {
  995.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  996.         }
  997.         if ( SAFE_MODE_ON == 0 )
  998.         {
  999.             
  1000.             if ( ! $ADMIN->rm_dir( $INFO['base_dir']."style_templates/".$IN['id'] ) )
  1001.             {
  1002.                 $ADMIN->error("Could not remove the template files, please check the CHMOD permissions to ensure that this script has the correct permissions to allow this");
  1003.             }
  1004.             
  1005.             if ( ! $ADMIN->rm_dir( $INFO['base_dir']."Skin/s".$IN['id'] ) )
  1006.             {
  1007.                 $ADMIN->error("Could not remove the template files, please check the CHMOD permissions to ensure that this script has the correct permissions to allow this");
  1008.             }
  1009.             
  1010.             $DB->query("DELETE FROM ibf_tmpl_names WHERE skid='".$IN['id']."'");
  1011.             
  1012.             $std->boink_it($SKIN->base_url."&act=templ");
  1013.             exit();
  1014.         }
  1015.         else
  1016.         {
  1017.             $DB->query("DELETE FROM ibf_tmpl_names WHERE skid='".$IN['id']."'");
  1018.             $ADMIN->info_screen("Safe mode restriction detected.<br>You will need to manually remove the directories 'Skin/s{$IN['id']}' and 'style_templates/{$IN['id']}' via FTP. The information has been removed from the database.");
  1019.         }
  1020.         
  1021.     }
  1022.     
  1023.     //-------------------------------------------------------------
  1024.     // EDIT TEMPLATES, STEP TWO
  1025.     //-------------------------------------------------------------
  1026.     
  1027.     function show_file()
  1028.     {
  1029.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1030.         
  1031.         $wrap = 'soft';
  1032.         
  1033.         if ($IN['rows'] != "")
  1034.         {
  1035.             $rows = $IN['rows'];
  1036.         }
  1037.         
  1038.         if ($IN['cols'] != "")
  1039.         {
  1040.             $cols = $IN['cols'];
  1041.         }
  1042.         
  1043.         if ($IN['wrap'] != "")
  1044.         {
  1045.             $wrap = $IN['wrap'];
  1046.         }
  1047.         
  1048.         $std->my_setcookie('ad_tempform', $rows."-".$cols."-".$wrap );
  1049.         
  1050.         //+-------------------------------
  1051.         
  1052.         if ($IN['id'] == "")
  1053.         {
  1054.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  1055.         }
  1056.         
  1057.         //+-------------------------------
  1058.         
  1059.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  1060.         
  1061.         if ( ! $row = $DB->fetch_row() )
  1062.         {
  1063.             $ADMIN->error("Could not query the information from the database");
  1064.         }
  1065.         
  1066.         $template = $root_path."style_templates/".$IN['id']."/".$IN['template_name'];
  1067.         
  1068.         
  1069.         if ( ! file_exists($template) )
  1070.         {
  1071.             $ADMIN->error("Cannot locate '$template', please check the paths and ensure the file and directories are correct.");
  1072.         }
  1073.         
  1074.         //+-------------------------------
  1075.         
  1076.         if ( ! is_writeable($template) )
  1077.         {
  1078.             $ADMIN->error("Cannot write into '$template', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  1079.         }
  1080.         
  1081.         //+-------------------------------
  1082.         
  1083.         if ($fh = @fopen( $template, 'r' ) )
  1084.         {
  1085.             $templ = fread( $fh, filesize($template) );
  1086.             fclose($fh);
  1087.         }
  1088.         else
  1089.         {
  1090.             if ( SAFE_MODE_ON == 0 )
  1091.             {
  1092.                 $ADMIN->error("Could not load $template, please ensure that the file is there and the CHMOD permissions are correct.");
  1093.             }
  1094.             else
  1095.             {
  1096.                 $ADMIN->info_screen("<b>Safe mode restriction detected</b><br>Due to the nature of your PHP installation, you may not be able to edit templates using the online editor");
  1097.             }
  1098.         }
  1099.         
  1100.         //+-------------------------------
  1101.         // Swop < and > into ascii entities
  1102.         // to prevent textarea breaking html
  1103.         //+-------------------------------
  1104.         
  1105.         $templ = preg_replace("/&/", "&", $templ );
  1106.         $templ = preg_replace("/</", "<", $templ );
  1107.         $templ = preg_replace("/>/", ">", $templ );
  1108.         
  1109.         
  1110.         
  1111.         //+-------------------------------
  1112.     
  1113.         $ADMIN->page_detail = "You may edit the HTML of this template.<br>Please DO NOT REMOVE OR EDIT the Invision board comment tags (example: <!--|IBF|table_structure|START|-->). Doing so may break the template file and your board. If in doubt, create a new skin and test the edits on that. These tags must also be on their own line, they cannot be embedded into the HTML";
  1114.         $ADMIN->page_title  = "Edit Template Set File: ".$IN['template_name']." in set: ".$row['skname'];
  1115.         
  1116.                                          
  1117.         //+-------------------------------
  1118.         //+-------------------------------
  1119.         
  1120.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doedit'    ),
  1121.                                                   2 => array( 'act'   , 'templ'     ),
  1122.                                                   3 => array( 'id'    , $IN['id']   ),
  1123.                                                   4 => array( 'name'  , $IN['template_name'] ),
  1124.                                          )      );
  1125.                                          
  1126.         //+-------------------------------
  1127.         
  1128.         $SKIN->td_header[] = array( " "   , "100%" );
  1129.  
  1130.         //+-------------------------------
  1131.         
  1132.         $ADMIN->html .= $SKIN->start_table( "The template" );
  1133.         
  1134.         $ADMIN->html .= $SKIN->add_td_basic( "<-- <a href='".$ADMIN->base_url."&act=templ&code=edit&id={$IN['id']}'>Go back to choose another template to edit in set '{$row['skname']}'</a>", "center", "catrow");
  1135.         
  1136.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1137.                                                     "<center>".$SKIN->form_textarea('template', $templ, $cols, $rows, $wrap)."</center>",
  1138.                                          )      );
  1139.                                          
  1140.         
  1141.                                          
  1142.         $ADMIN->html .= $SKIN->end_form("Update this file");
  1143.                                          
  1144.         $ADMIN->html .= $SKIN->end_table();
  1145.         
  1146.         $ADMIN->output();
  1147.         
  1148.         
  1149.     }
  1150.     
  1151.     //-------------------------------------------------------------
  1152.     // EDIT TEMPLATES, STEP ONE
  1153.     //-------------------------------------------------------------
  1154.     
  1155.     function do_form($method='edit', $new_id="")
  1156.     {
  1157.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1158.         
  1159.         if ($new_id != "")
  1160.         {
  1161.             $IN['id'] = $new_id;
  1162.         }
  1163.         
  1164.         if ($IN['id'] == "")
  1165.         {
  1166.             $ADMIN->error("You must specify an existing template set ID, go back and try again");
  1167.         }
  1168.         
  1169.         //+-------------------------------
  1170.         
  1171.         $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'");
  1172.         
  1173.         if ( ! $row = $DB->fetch_row() )
  1174.         {
  1175.             $ADMIN->error("Could not query the information from the database");
  1176.         }
  1177.         
  1178.         $templates_dir = $INFO['base_dir']."style_templates/".$IN['id'];
  1179.         
  1180.         $form_array = array();
  1181.         
  1182.         //+-------------------------------
  1183.         
  1184.         if ($method != 'add')
  1185.         {
  1186.             if ( ! is_writeable($templates_dir) )
  1187.             {
  1188.                 $ADMIN->error("Cannot write into '$templates_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  1189.             }
  1190.         }
  1191.         
  1192.         //+-------------------------------
  1193.         
  1194.         if ( is_dir($templates_dir) )
  1195.         {
  1196.             $handle = opendir($templates_dir);
  1197.             
  1198.             while (($filename = readdir($handle)) !== false)
  1199.             {
  1200.                 if (($filename != ".") && ($filename != ".."))
  1201.                 {
  1202.                     if (preg_match("/^index/", $filename))
  1203.                     {
  1204.                         continue;
  1205.                     }
  1206.                     
  1207.                     if (preg_match("/\.html$/", $filename))
  1208.                     {
  1209.                         $form_array[] = array( $filename, $filename );
  1210.                     }
  1211.                 }
  1212.             }
  1213.                 
  1214.             closedir($handle);
  1215.         }
  1216.         
  1217.         if ($row['author'] and $row['email'])
  1218.         {
  1219.             $author = "<br><br>This template set <b>'{$row['skname']}'</b> was created by <a href='mailto:{$row['email']}' target='_blank'>{$row['author']}</a>";
  1220.         }
  1221.         else if ($row['author'])
  1222.         {
  1223.             $author = "<br><br>This template set <b>'{$row['skname']}'</b> was created by {$row['author']}";
  1224.         }
  1225.         
  1226.         if ($row['url'])
  1227.         {
  1228.             $url = "<br><br>Authors website: <a href='{$row['url']}' target='_blank'>{$row['url']}</a>";
  1229.         }
  1230.         
  1231.         //+-------------------------------
  1232.     
  1233.         $ADMIN->page_detail = "Please choose which section you wish to edit below.$author $url";
  1234.         $ADMIN->page_title  = "Edit Template sets";
  1235.         
  1236.         //+-------------------------------
  1237.         
  1238.         //+-------------------------------
  1239.         
  1240.         $ADMIN->html .= $SKIN->js_no_specialchars();
  1241.         
  1242.         
  1243.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'editinfo'    ),
  1244.                                                   2 => array( 'act'   , 'templ'       ),
  1245.                                                   3 => array( 'id'    , $IN['id']     ),
  1246.                                          ), "theAdminForm", "onSubmit=\"return no_specialchars('templates')\""      );
  1247.                                          
  1248.         //+-------------------------------
  1249.         
  1250.         $SKIN->td_header[] = array( " "   , "60%" );
  1251.         $SKIN->td_header[] = array( " "   , "40%" );
  1252.  
  1253.         //+-------------------------------
  1254.         
  1255.         $ADMIN->html .= $SKIN->start_table( "Edit template information" );
  1256.         
  1257.                                          
  1258.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1259.                                                     "<b>Template Set Name</b>",
  1260.                                                     $SKIN->form_input('skname', $row['skname']),
  1261.                                          )      );
  1262.                                          
  1263.         if ($method == 'add')
  1264.         {
  1265.                                          
  1266.             $ADMIN->html .= $SKIN->add_td_row( array( 
  1267.                                                         "<b>Template set author name:</b>",
  1268.                                                         $SKIN->form_input('author', $row['author']),
  1269.                                              )      );
  1270.                                              
  1271.             $ADMIN->html .= $SKIN->add_td_row( array( 
  1272.                                                         "<b>Template set author email:</b>",
  1273.                                                         $SKIN->form_input('email', $row['email']),
  1274.                                              )      );
  1275.                                              
  1276.             $ADMIN->html .= $SKIN->add_td_row( array( 
  1277.                                                         "<b>Template set author webpage:</b>",
  1278.                                                         $SKIN->form_input('url', $row['url']),
  1279.                                              )      );
  1280.                                          
  1281.         }
  1282.                                          
  1283.         $ADMIN->html .= $SKIN->end_form("Edit template set details");
  1284.                                          
  1285.         $ADMIN->html .= $SKIN->end_table();
  1286.                                          
  1287.         //+-------------------------------
  1288.         //+-------------------------------
  1289.         
  1290.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'edit2'    ),
  1291.                                                   2 => array( 'act'   , 'templ'     ),
  1292.                                                   3 => array( 'id'    , $IN['id']   ),
  1293.                                          ), 'secondform'     );
  1294.                                          
  1295.         //+-------------------------------
  1296.         
  1297.         $SKIN->td_header[] = array( " "   , "60%" );
  1298.         $SKIN->td_header[] = array( " "   , "40%" );
  1299.  
  1300.         //+-------------------------------
  1301.         
  1302.         if ( $cookie = $std->my_getcookie('ad_tempform') )
  1303.         {
  1304.             list($rows, $cols, $wrap) = explode( '-', $cookie );
  1305.         }
  1306.         
  1307.         $cols = $cols ? $cols : 80;
  1308.         $rows = $rows ? $rows : 40;
  1309.         $wrap = $wrap ? $wrap : 'soft';
  1310.         
  1311.         $ADMIN->html .= $SKIN->start_table( "Edit templates in set '".$row['skname']."'" );
  1312.         
  1313.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1314.                                                     "<b>Please select a template file to edit</b>",
  1315.                                                     $SKIN->form_dropdown('template_name', $form_array),
  1316.                                          )      );
  1317.                                          
  1318.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1319.                                                     "<b>Text area rows:</b>",
  1320.                                                     $SKIN->form_input('rows', $rows),
  1321.                                          )      );
  1322.                                          
  1323.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1324.                                                     "<b>Text area columns:</b>",
  1325.                                                     $SKIN->form_input('cols', $cols),
  1326.                                          )      );
  1327.                                          
  1328.         $ADMIN->html .= $SKIN->add_td_row( array( 
  1329.                                                     "<b>Text area wrapping:</b>",
  1330.                                                     $SKIN->form_dropdown('wrap', 
  1331.                                                     array( 0 => array( 'soft', 'soft'),
  1332.                                                            1 => array( 'virtual', 'virtual'),
  1333.                                                            2 => array( 'off', 'off'),
  1334.                                                          ),
  1335.                                                     $wrap),
  1336.                                          )      );
  1337.                                          
  1338.         $ADMIN->html .= $SKIN->end_form("Edit this template file");
  1339.                                          
  1340.         $ADMIN->html .= $SKIN->end_table();
  1341.                                          
  1342.         //+-------------------------------
  1343.         //+-------------------------------
  1344.         
  1345.         $ADMIN->output();
  1346.         
  1347.         
  1348.     }
  1349.     
  1350.     //-------------------------------------------------------------
  1351.     // SHOW CURRENT TEMPLATE PACKS
  1352.     //-------------------------------------------------------------
  1353.     
  1354.     function list_current()
  1355.     {
  1356.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1357.         
  1358.         $form_array = array();
  1359.     
  1360.         $ADMIN->page_detail = "The skin templates contain the all the board HTML. You can edit each section individually via the online editor, or download the template files to edit in another editor.";
  1361.         $ADMIN->page_title  = "Manage Template Sets";
  1362.         
  1363.         //+-------------------------------
  1364.         
  1365.         $SKIN->td_header[] = array( "Title"        , "40%" );
  1366.         $SKIN->td_header[] = array( "Allocation"   , "30%" );
  1367.         $SKIN->td_header[] = array( "Export"       , "10%" );
  1368.         $SKIN->td_header[] = array( "Edit"         , "10%" );
  1369.         $SKIN->td_header[] = array( "Remove"       , "10%" );
  1370.         
  1371.         //+-------------------------------
  1372.         
  1373.         $DB->query("SELECT DISTINCT(s.set_id), t.skid, t.skname from ibf_tmpl_names t, ibf_skins s WHERE s.set_id=t.skid ORDER BY t.skname ASC");
  1374.         
  1375.         $used_ids = array();
  1376.         $show_array = array();
  1377.         
  1378.         if ( $DB->get_num_rows() )
  1379.         {
  1380.         
  1381.             $ADMIN->html .= $SKIN->start_table( "Current Template sets In Use" );
  1382.             
  1383.             while ( $r = $DB->fetch_row() )
  1384.             {
  1385.             
  1386.                 $show_array[ $r['skid'] ] .= stripslashes($r['skname'])."<br>";
  1387.             
  1388.                 if ( in_array( $r['skid'], $used_ids ) )
  1389.                 {
  1390.                     continue;
  1391.                 }
  1392.                 
  1393.                 $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['skname'])."</b>",
  1394.                                                           "<#X-{$r['skid']}#>",
  1395.                                                           "<center><a href='".$SKIN->base_url."&act=templ&code=export&id={$r['skid']}'>Export</a></center>",
  1396.                                                           "<center><a href='".$SKIN->base_url."&act=templ&code=edit&id={$r['skid']}'>Edit</a></center>",
  1397.                                                           "<i>Deallocate before removing</i>",
  1398.                                                  )      );
  1399.                                                    
  1400.                 $used_ids[] = $r['skid'];
  1401.                 
  1402.                 $form_array[] = array( $r['skid'], $r['skname'] );
  1403.                 
  1404.             }
  1405.             
  1406.             foreach( $show_array as $idx => $string )
  1407.             {
  1408.                 $string = preg_replace( "/<br>$/", "", $string );
  1409.                 
  1410.                 $ADMIN->html = preg_replace( "/<#X-$idx#>/", "$string", $ADMIN->html );
  1411.             }
  1412.             
  1413.             $ADMIN->html .= $SKIN->end_table();
  1414.         }
  1415.         
  1416.         if ( count($used_ids) > 0 )
  1417.         {
  1418.         
  1419.             $DB->query("SELECT skid, skname FROM ibf_tmpl_names WHERE skid NOT IN(".implode(",",$used_ids).")");
  1420.         
  1421.             if ( $DB->get_num_rows() )
  1422.             {
  1423.             
  1424.                 $SKIN->td_header[] = array( "Title"  , "70%" );
  1425.                 $SKIN->td_header[] = array( "Export"   , "10%" );
  1426.                 $SKIN->td_header[] = array( "Edit"   , "10%" );
  1427.                 $SKIN->td_header[] = array( "Remove" , "10%" );
  1428.             
  1429.                 $ADMIN->html .= $SKIN->start_table( "Current Unallocated Template sets" );
  1430.                 
  1431.                 $ADMIN->html .= $SKIN->js_checkdelete();
  1432.                 
  1433.                 while ( $r = $DB->fetch_row() )
  1434.                 {
  1435.                     
  1436.                     $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['skname'])."</b>",
  1437.                                                               "<center><a href='".$SKIN->base_url."&act=templ&code=export&id={$r['skid']}'>Export</a></center>",
  1438.                                                               "<center><a href='".$SKIN->base_url."&act=templ&code=edit&id={$r['skid']}'>Edit</a></center>",
  1439.                                                               "<center><a href='javascript:checkdelete(\"act=templ&code=remove&id={$r['skid']}\")'>Remove</a></center>",
  1440.                                                      )      );
  1441.                                                      
  1442.                     $form_array[] = array( $r['skid'], $r['skname'] );
  1443.                                                        
  1444.                 }
  1445.                 
  1446.                 $ADMIN->html .= $SKIN->end_table();
  1447.             }
  1448.         }
  1449.         
  1450.         //+-------------------------------
  1451.         //+-------------------------------
  1452.         
  1453.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add'     ),
  1454.                                                   2 => array( 'act'   , 'templ'    ),
  1455.                                          )      );
  1456.         
  1457.         $SKIN->td_header[] = array( " "  , "40%" );
  1458.         $SKIN->td_header[] = array( " "  , "60%" );
  1459.         
  1460.         $ADMIN->html .= $SKIN->start_table( "Create New Template Set" );
  1461.             
  1462.         //+-------------------------------
  1463.         
  1464.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new Template set on...</b>" ,
  1465.                                                     $SKIN->form_dropdown( "id", $form_array)
  1466.                                  )      );
  1467.         
  1468.         $ADMIN->html .= $SKIN->end_form("Create new Template set");
  1469.                                          
  1470.         $ADMIN->html .= $SKIN->end_table();
  1471.         
  1472.         //+-------------------------------
  1473.         //+-------------------------------
  1474.         
  1475.         
  1476.         //+-------------------------------
  1477.         //+-------------------------------
  1478.         
  1479.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'tools'     ),
  1480.                                                   2 => array( 'act'   , 'templ'    ),
  1481.                                          )      );
  1482.         
  1483.         $SKIN->td_header[] = array( "Tool"  , "50%" );
  1484.         $SKIN->td_header[] = array( "run on template set"  , "50%" );
  1485.         
  1486.         $extra = "";
  1487.         
  1488.         if ( SAFE_MODE_ON == 1)
  1489.         {
  1490.             $extra = "<br><span id='detail'>WARNING: Safe mode restrictions detected, some of these tools will not work</span>";
  1491.         }
  1492.         
  1493.         $ADMIN->html .= $SKIN->start_table( "Template Tools".$extra );
  1494.             
  1495.         //+-------------------------------
  1496.         
  1497.         $ADMIN->html .= $SKIN->add_td_row( array( $SKIN->form_dropdown( "tool",
  1498.                                                                         array(
  1499.                                                                                 0 => array( 'conf', 'Rebuild Master Config (remap function call data)' ),
  1500.                                                                                 1 => array( 'tmpl', 'Rebuild editable templates from php skin files'   ),
  1501.                                                                                 2 => array( 'skin', 'Rebuild php skin files from editable templates'   ),
  1502.                                                                              )
  1503.                                                                       ) ,
  1504.                                                     $SKIN->form_dropdown( "id", $form_array)
  1505.                                  )      );
  1506.         
  1507.         $ADMIN->html .= $SKIN->end_form("Run Tool");
  1508.                                          
  1509.         $ADMIN->html .= $SKIN->end_table();
  1510.         
  1511.         //+-------------------------------
  1512.         //+-------------------------------
  1513.         
  1514.         $ADMIN->output();
  1515.     
  1516.     }
  1517.     
  1518.     function convert_tags($t="")
  1519.     {
  1520.         if ($t == "")
  1521.         {
  1522.             return "";
  1523.         }
  1524.         
  1525.         $t = preg_replace( "/{?\\\$ibforums->base_url}?/"            , "{ibf.script_url}"   , $t );
  1526.         $t = preg_replace( "/{?\\\$ibforums->session_id}?/"          , "{ibf.session_id}"   , $t );
  1527.         $t = preg_replace( "/{?\\\$ibforums->skin\['?(\w+)'?\]}?/"   , "{ibf.skin.\\1}"      , $t );
  1528.         $t = preg_replace( "/{?\\\$ibforums->lang\['?(\w+)'?\]}?/"   , "{ibf.lang.\\1}"      , $t );
  1529.         $t = preg_replace( "/{?\\\$ibforums->vars\['?(\w+)'?\]}?/"   , "{ibf.vars.\\1}"      , $t );
  1530.         $t = preg_replace( "/{?\\\$ibforums->member\['?(\w+)'?\]}?/" , "{ibf.member.\\1}"    , $t );
  1531.         
  1532.         return $t;
  1533.         
  1534.     }
  1535.     
  1536.     function unconvert_tags($t="")
  1537.     {
  1538.         if ($t == "")
  1539.         {
  1540.             return "";
  1541.         }
  1542.         
  1543.         $t = preg_replace( "/{ibf\.script_url}/i"   , '{$ibforums->base_url}'         , $t);
  1544.         $t = preg_replace( "/{ibf\.session_id}/i"   , '{$ibforums->session_id}'       , $t);
  1545.         $t = preg_replace( "/{ibf\.skin\.(\w+)}/"   , '{$ibforums->skin[\''."\\1".'\']}'   , $t);
  1546.         $t = preg_replace( "/{ibf\.lang\.(\w+)}/"   , '{$ibforums->lang[\''."\\1".'\']}'   , $t);
  1547.         $t = preg_replace( "/{ibf\.vars\.(\w+)}/"   , '{$ibforums->vars[\''."\\1".'\']}'   , $t);
  1548.         $t = preg_replace( "/{ibf\.member\.(\w+)}/" , '{$ibforums->member[\''."\\1".'\']}' , $t);
  1549.         
  1550.         return $t;
  1551.         
  1552.     }
  1553.     
  1554.     
  1555. }
  1556.  
  1557.  
  1558. ?>